// packageB/pages/nineAmount/nineAmount.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    user_img: '/img/userImg.png',
    user: {
      userName: '用户名'
    },
    totalMoney: '0.00', //总收益
    daiMoney: '0.00', //代理商返现金额
    invitesMoney: '0.00', //提现金额
    profitMoney: '0.00', //剩余利润
    myProfitMoney: '0.00', //我的利润
    userType: -1,
  },

  getList() {
    wx.showLoading({
      title: '加载中',
    })
    var that = this;
    var url = app.globalData.url + "nine/getNineAmount";
    app.wxRequest(url, {}, res => {
      console.log(res);
      if (res.flag) {
        var totalList = res.data.userList,
          totalMoney = 0,
          invitesList = res.data.nineInvites,
          invitesMoney = 0,
          profitMoney = 0,
          myProfitMoney = 0,
          daiMoney = res.data.moneys;
        totalList.forEach(ele => {
          totalMoney += ele.inviteMoney
        });
        invitesList.forEach(ele => {
          invitesMoney += ele.getMoney
        });

        profitMoney = totalMoney * 1 - invitesMoney * 1 - daiMoney * 1
        myProfitMoney = profitMoney / 3
        console.log(totalMoney.toFixed(2));
        console.log(invitesMoney.toFixed(2));
        console.log(profitMoney.toFixed(2));
        console.log(myProfitMoney);

        that.setData({
          myProfitMoney: myProfitMoney.toFixed(2), //我的利润
          totalMoney: totalMoney.toFixed(2), //总收益
          invitesMoney: invitesMoney.toFixed(2), //提现金额
          daiMoney: daiMoney.toFixed(2), // 代理商返现金额
          profitMoney: profitMoney.toFixed(2) //总利润
        })
        wx.hideLoading()
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options);
    if (options.obj !== undefined) {
      var obj = JSON.parse(options.obj)
      this.setData({
        user: obj,
        userType: app.globalData.userType,
      })
    }
    this.getList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})